<?php
$idUser = $_SESSION['id'];
$tabela = "tb_menu";
$tabela_itens = "tb_menu_item";
$conn = new CONEXAO();

$conn->Conecta();

	$menus = $conn->grav("select * from $tabela");

$conn->Desconecta();


?>
<div>

<ul class="menu">

<?php
	
	if(is_array($menus)){

			foreach($menus as $menu){

				if($menu['link']!=""){
					
					$link = $menu['link']; 
				
				}
				else{
				
				$link = '#'; 
				
				}
?>

				<li class="top">
						
						<a href="$link" class="top_link">
							
							<span><?php echo $menu['nome'];?></span>
						
						</a>
<?php

$conn->Conecta();

$menuitens = $conn->grav("select * from $tabela_itens where menu = ".$menu['id']."");

$conn->Desconecta();

	if(is_array($menuitens) && (count($menuitens)>0)){

?>
	
	<ul class="sub">

<?php
	
			foreach($menuitens as $menuitem){
?>
				<li><a href="<?php echo $menuitem['link'];?>"><?php echo $menuitem['nome'];?></a></li>
<?php 
			}
?>

			</ul>
<?php
	}
?>
		</li>
<?php
}

}
?>

	<li class="top"><a href="#" id="mudaSenha" class="top_link"><span>Mudar Senha</span></a></li>
	<li class="top"><a href="logout.php" class="top_link"><span>Sair</span></a></li>
</ul>
</div>
